﻿using HKB.Common;
using HKB.Web;
using HKB.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;

public partial class Admin_Admin_Skin : Admin, IRequiresSessionState
{
    public string m_SkinType = "";
    private SkinBll _myskin = null;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    protected SkinBll myskin
    {
        get
        {
            SkinBll myskin;
            if (this._myskin == null)
            {
                this._myskin = new SkinBll(this.conn);
                myskin = this._myskin;
            }
            else
            {
                myskin = this._myskin;
            }
            return myskin;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.admin.CheckAdminPower(12))
        {
            base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Skin");
            base.WriteRightErrMsg();
        }
        this.m_SkinType = Fetch.Get("SkinType", "string");
        if (string.IsNullOrEmpty(this.m_SkinType))
        {
            this.m_SkinType = "Index";
        }
        this.GridView1.DataSource = this.myskin.GetProSkinBySkinType(this.m_SkinType);
        this.GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
        foreach (GridViewRow gridViewRow in this.GridView1.Rows)
        {
            string text = gridViewRow.Cells[4].Text;
            LinkButton linkButton = (LinkButton)gridViewRow.FindControl("btnDelete");
            LinkButton linkButton2 = (LinkButton)gridViewRow.FindControl("SetIsDefault");
            if (text == "0" || text.ToLower() == "false")
            {
                gridViewRow.Cells[4].Text = Language.Get("Common/No");
            }
            else
            {
                gridViewRow.Cells[4].Text = Language.Get("Common/Yes");
                linkButton.OnClientClick = "";
                linkButton.Enabled = false;
                linkButton2.OnClientClick = "";
                linkButton2.Enabled = false;
            }
            if (!base.admin.CheckAdminPower(12))
            {
                HyperLink hyperLink = (HyperLink)gridViewRow.FindControl("btnUpdateSkin");
                HyperLink hyperLink2 = (HyperLink)gridViewRow.FindControl("btnAddSkin");
                hyperLink.Enabled = false;
                hyperLink2.Enabled = false;
            }
            HyperLink hyperLink3 = (HyperLink)gridViewRow.FindControl("SkinName");
            if (hyperLink3.ToolTip != "" && hyperLink3.ToolTip != null && hyperLink3.ToolTip.Length > 2)
            {
                hyperLink3.ToolTip = "<img src=\"" + hyperLink3.ToolTip + "\"/>";
            }
            else
            {
                hyperLink3.ToolTip = "暂无预览图";
            }
        }
    }
    protected void Command_OnClick(object sender, CommandEventArgs e)
    {
        if (!base.admin.CheckAdminPower(12))
        {
            base.WriteLog("Check", Language.GetAdminMsg("Log/Access", "0"), "Identify");
            base.WriteRightErrMsg();
        }
        if (e.CommandName != null && e.CommandArgument != null)
        {
            string[] array = e.CommandArgument.ToString().Split(new char[]
			{
				','
			});
            this.m_SkinType = array[1];
            int num = Convert.ToInt32(array[0]);
            if (num <= 0)
            {
                this.WriteErrMsg("", Language.Get("Common/ParamErr", "SkinID"), "");
            }
            if (e.CommandName.ToString() == "DelSkin")
            {
                this.myskin.DeleteSkin(num);
                this.GridView1.DataSource = this.myskin.GetProSkinBySkinType(this.m_SkinType);
                this.GridView1.DataBind();
            }
            else
            {
                if (e.CommandName.ToString() == "SetIsDefault")
                {
                    this.myskin.SetIsDefault(num);
                    this.GridView1.DataSource = this.myskin.GetProSkinBySkinType(this.m_SkinType);
                    this.GridView1.DataBind();
                }
            }
        }
    }
}
